package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.base.model.User;
import com.yunfeisoft.business.dao.inter.RoomDisinfectionRecordsDao;
import com.yunfeisoft.business.model.Elder;
import com.yunfeisoft.business.model.Room;
import com.yunfeisoft.business.model.RoomDisinfectionRecords;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * ClassName: RoomDisinfectionRecordsDaoImpl
 * Description: 房间周卫生和消毒记录表Dao实现
 * Author: Jackie liu
 * Date: 2020-05-22
 */
@Repository
public class RoomDisinfectionRecordsDaoImpl extends BaseDaoImpl<RoomDisinfectionRecords, String> implements RoomDisinfectionRecordsDao {

    @Override
    public Page<RoomDisinfectionRecords> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        wb.setOrderByWithDesc("createTime");
        if (params != null) {
            initPageParam(wb, params);
            if (!ObjectUtils.isEmpty(params.get("floorNum"))) {
                wb.andEquals("r.floorNum", params.get("floorNum"));
            }
            if (!ObjectUtils.isEmpty(params.get("roomNum"))) {
                wb.andEquals("r.roomNum", params.get("roomNum"));
            }
        }
        SelectBuilder builder = getSelectBuilder("o");
        builder.column("r.floorNum as floorNum")
                .column("r.roomNum as roomNum")
                .join(Room.class)
                .alias("r")
                .on("r.id = o.roomId").build();
        builder.column("u.name createName")
                .join(User.class).alias("u")
                .on("u.id = o.createId").build();
        return queryPage(builder.getSql(), wb);
    }
}